#!/bin/bash

#Se chequea que todo este bien
if [ $# -ne "1" ]
then
	echo "USO: " 
	echo "Hacer solo los pings: ${0} -p"
	echo "Hacer solo los traceroutes: ${0} -t"
	echo "Hacer pings y traceroutes: ${0} -a"
	exit 0
fi

declare -a ips=(
"10.11.23.1"
"172.3.1.193"
"172.3.1.197"
"10.11.23.2"
"10.134.5.129"
"10.11.23.3"
"10.134.5.161"
"10.11.23.4"
"192.168.53.2"
"10.11.23.5"
"192.168.53.3"
"10.11.23.6"
"192.168.53.4"
"192.168.53.5"
"137.43.1.1"
"10.11.23.7"
"192.168.53.1"
"10.134.1.1"
"10.134.5.162"
"172.3.1.194"
"172.3.1.201"
"10.134.1.2"
"10.134.13.161"
"10.134.1.3"
"10.134.13.162"
"10.134.13.1"
"10.134.5.165"
"10.134.1.4"
"10.134.13.163"
"10.134.13.130"
"10.134.13.2"
"10.134.13.3"
"137.43.1.5"
"10.134.1.5"
"10.134.1.130"
"10.134.13.111"
"10.134.13.193"
"137.43.1.9"
"10.9.12.193"
"10.134.5.166"
"172.3.1.198"
"172.3.1.202"
"10.9.12.194"
"10.11.22.2"
"10.134.13.225"
"10.9.12.195"
"10.11.22.3"
"10.11.22.4"
"10.134.13.194"
"10.9.12.196"
"10.11.22.1"
)

declare -a names=(
"R1"
"R1"
"R1"
"R2"
"R2"
"R3"
"R3"
"R4"
"R4"
"R5"
"R5"
"Rv 4-5"
"Rv 4-5"
"R6"
"R6"
"Host A"
"WebServer"
"R7"
"R7"
"R7"
"R7"
"R8"
"R8"
"R9"
"R9"
"R9"
"R9"
"Rv 8-9"
"Rv 8-9"
"R10"
"R10"
"R11"
"R11"
"Host B"
"TelServer I"
"TelServer II"
"R12"
"R12"
"R13"
"R13"
"R13"
"R13"
"R14"
"R14"
"R14"
"R15"
"R15"
"R16"
"R16"
"Host C"
"FTPServer"
)

# ping a todas las ips de la topologia (incluye hosts y servers desconectados)
if [ "$1" = "-a" ] || [ "$1" = "-p" ] ; then
	i=0
	while [ $i -lt ${#ips[*]} ]; do
	    echo "Ping a: ${ips[$i]} (${names[$i]})"
	    ping -q -c3 -W 7 ${ips[$i]} > /dev/null
	    if [ $? -eq 0 ]
	    then
		echo "  OK"
	    else
	    	echo "  FAILED"
	    fi
	    
	    i=$(( $i + 1));
	done
fi

if [ "$1" = "-a" ] || [ "$1" = "-t" ] ; then
	# traceroutes a todas las ips
	i=0
	while [ $i -lt ${#ips[*]} ]; do
	    echo "Traceroute a: ${ips[$i]} (${names[$i]})"
	    traceroute -m 10 ${ips[$i]}
	    i=$(( $i + 1));
	done
fi

exit 0

